{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 初始化当前目录为一个git仓库\n",
    "git init \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#初始化/var/code为一个git仓库\n",
    "git init /var/code "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将当前目录下的所有文件添加到git仓库暂存区\n",
    "git add . "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将/var/code/file.txt添加到git仓库暂存区\n",
    "git add /var/code/file.txt "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#查看远程仓库的信息\n",
    "git remote -v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 添加远程仓库\n",
    "git remote add gitee git@gitee.com:pyshcode/jupyter.git "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除远程仓库\n",
    "git remote rm gitee"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 推送到远程仓库\n",
    "git push -u gitee master"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 克隆远程仓库\n",
    "git clone git@gitee.com:pyshcode/jupyter.git"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#克隆远程仓库到指定目录\n",
    "git clone git@gitee.com:pyshcode/jupyter.git /var/code/jupyter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看仓库当前状态\n",
    "git status"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 提交暂存区的修改到仓库\n",
    "git commit -m \"second commit\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 下载远程仓库的某个版本\n",
    "git fetch gitee master"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 下载远程代码到本地\n",
    "git pull gitee master"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 推送本地修改到远程仓库\n",
    "git push gitee master"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 比较文件差异\n",
    "git diff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将工作区回退到上一个版本，--hard参数会撤销工作区所有未提交的修改\n",
    "git reset --hard HEAD^\n",
    "# 回退到指定版本\n",
    "git reset 052e8f8\n",
    "# 回退指定文件到上一个版本\n",
    "git reset HEAD file.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看历史提交记录\n",
    "git log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看某个版本的历史提交记录\n",
    "git log v1.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 以列表的形式查看历史提交记录\n",
    "git blame file.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#生成ssh密钥,将密钥上传到gitee\n",
    "ssh-keygen -t rsa -C \"gitee\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#设置git用户名\n",
    "git config --global user.name \"gitee\" \n",
    "#设置git用户邮箱\n",
    "git config --global user.email \"example@qq.com\" "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 显示当前用户的git配置\n",
    "git config --list"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
